package com.sneaker.shower.config;

import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @author Hechangjian
 * @version 1.0
 * @className WxMpConfiguration
 * @date 2019/07/26 18:21
 * @description 微信公众号MpService初始化类
 * @program bath
 */
@Configuration
@EnableConfigurationProperties(WxMpProperties.class)
public class WxMpConfiguration {

    private final WxMpProperties wxMpProperties;

    public WxMpConfiguration(WxMpProperties wxMpProperties) {
        this.wxMpProperties = wxMpProperties;
    }

    @Bean
    public WxMpDefaultConfigImpl getWxConfiguration() {
        WxMpDefaultConfigImpl wxMpDefaultConfig = new WxMpDefaultConfigImpl();
        wxMpDefaultConfig.setAppId(wxMpProperties.getAppId());
        wxMpDefaultConfig.setSecret(wxMpProperties.getAppSecret());
        wxMpDefaultConfig.setToken(wxMpProperties.getToken());
        wxMpDefaultConfig.setAesKey(wxMpProperties.getAESKey());
        return wxMpDefaultConfig;
    }

    @Bean
    public WxMpService wxMpService() {
        WxMpService wxMpService = new WxMpServiceImpl();
        wxMpService.setWxMpConfigStorage(getWxConfiguration());
        return wxMpService;
    }

}
